/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/logiline/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=10;
    json.url = url ;
    json.param = [
        {"name": "id", "value": $.trim($("#id").val())},
        {"name": "logisticsAreaId", "value": $.trim($("#logisticsAreaId").val())},
        {"name": "logisticsAreaCode", "value": $.trim($("#logisticsAreaCode").val())},
        {"name": "logisticsAreaLineLevel", "value": $.trim($("#logisticsAreaLineLevel").val())},
        {"name": "logisticsPointId", "value": $.trim($("#logisticsPointId").val())},
        {"name": "logisticsPointCode", "value": $.trim($("#logisticsPointCode").val())},
        {"name": "countryCode", "value": $.trim($("#countryCode").val())},
        {"name": "provinceCode", "value": $.trim($("#provinceCode").val())},
        {"name": "cityCode", "value": $.trim($("#cityCode").val())},
        {"name": "countyCode", "value": $.trim($("#countyCode").val())},
    ];
    json.columns = [
        {
            "mData": "logilineCode", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEditLogiline(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='deleteLogiline(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
        {"mData": "id", "sClass": "text-center"},
        {"mData": "logisticsAreaId", "sClass": "text-center"},
        {"mData": "logisticsAreaCode", "sClass": "text-center"},
        {"mData": "logisticsAreaLineLevel", "sClass": "text-center"},
        {"mData": "logisticsPointId", "sClass": "text-center"},
        {"mData": "logisticsPointCode", "sClass": "text-center"},
        {"mData": "countryCode", "sClass": "text-center"},
        {"mData": "provinceCode", "sClass": "text-center"},
        {"mData": "cityCode", "sClass": "text-center"},
        {"mData": "countyCode", "sClass": "text-center"},
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
	$("#id").val('');
	$("#logisticsAreaId").val('');
	$("#logisticsAreaCode").val('');
	$("#logisticsAreaLineLevel").val('');
	$("#logisticsPointId").val('');
	$("#logisticsPointCode").val('');
	$("#countryCode").val('');
	$("#provinceCode").val('');
	$("#cityCode").val('');
	$("#countyCode").val('');
}

/*删除数据*/
function deleteLogiline(logilineCode){
    var _url=getBasePath()+'/mdm/logiline/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var logiline={};
        logiline.logilineCode=logilineCode;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(logiline),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除物流运作区域数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEditLogiline(logilineCode){
    var _url=getBasePath()+'/mdm/logiline/toEdit.htm?logilineCode='+logilineCode;
    location.href=_url;
}

/*编辑数据*/
function editLogiline(){
    $validator =$("#logiline_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/logiline/edit.json';
    var logiline={};
	logiline.id=$("#id").val();
	logiline.logisticsAreaId=$("#logisticsAreaId").val();
	logiline.logisticsAreaCode=$("#logisticsAreaCode").val();
	logiline.logisticsAreaLineLevel=$("#logisticsAreaLineLevel").val();
	logiline.logisticsPointId=$("#logisticsPointId").val();
	logiline.logisticsPointCode=$("#logisticsPointCode").val();
	logiline.countryCode=$("#countryCode").val();
	logiline.provinceCode=$("#provinceCode").val();
	logiline.cityCode=$("#cityCode").val();
	logiline.countyCode=$("#countyCode").val();

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(logiline),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑物流运作区域数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/* 跳转明细页面*/
function toDetailPage(code){
    var _url=getBasePath()+'/mdm/logiline/detail.htm?logilineCode='+code;
    location.href=_url;
}
/*跳转新增数据页面*/
function toAddLogiline(){
    var _url=getBasePath()+'/mdm/logiline/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function saveLogiline(){
    $validator =$("#logiline_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/logiline/add.json';
    var logiline={};
	logiline.id=$("#id").val();
	logiline.logisticsAreaId=$("#logisticsAreaId").val();
	logiline.logisticsAreaCode=$("#logisticsAreaCode").val();
	logiline.logisticsAreaLineLevel=$("#logisticsAreaLineLevel").val();
	logiline.logisticsPointId=$("#logisticsPointId").val();
	logiline.logisticsPointCode=$("#logisticsPointCode").val();
	logiline.countryCode=$("#countryCode").val();
	logiline.provinceCode=$("#provinceCode").val();
	logiline.cityCode=$("#cityCode").val();
	logiline.countyCode=$("#countyCode").val();
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(logiline),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增物流运作区域数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/logiline/list.htm';
}





